package com.huilian.iotbox.data.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.huilian.iotbox.data.dao.CommodityStockRecordItemCommonDao;
import com.huilian.iotbox.data.dto.CommodityStockRecordItemDto;
import com.huilian.iotbox.data.service.CommodityStockRecordItemCommonService;
import com.huilian.iotbox.data.vo.CommodityStockRecordItemVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class CommodityStockRecordItemCommonServiceImpl implements CommodityStockRecordItemCommonService {
    @Autowired
    private CommodityStockRecordItemCommonDao commodityStockRecordItemDao;

    @Override
    public int add(CommodityStockRecordItemDto commodityStockRecordItemDto) {
        return commodityStockRecordItemDao.add(commodityStockRecordItemDto);
    }

    @Override
    public List<CommodityStockRecordItemVo> findRecordItem(CommodityStockRecordItemDto commodityStockRecordDto) {
        return commodityStockRecordItemDao.findByMerchantStoreIdAndCommodityId(commodityStockRecordDto);
    }

    @Override
    public PageInfo<CommodityStockRecordItemVo> findRecordItemPageInfo(CommodityStockRecordItemDto commodityStockRecordDto) {
        PageHelper.orderBy("csri.createTime DESC");
        PageHelper.startPage(commodityStockRecordDto.getPageNum(), commodityStockRecordDto.getPageSize(), true);
        List<CommodityStockRecordItemVo> list = commodityStockRecordItemDao.findByMerchantStoreIdAndCommodityId(commodityStockRecordDto);
        return new PageInfo<>(list);
    }

    @Override
    public List<CommodityStockRecordItemVo> findByCommodityStockId(CommodityStockRecordItemDto commodityStockRecordDto) {
        return commodityStockRecordItemDao.findByCommodityStockId(commodityStockRecordDto);
    }

}
